package ljj.rollcall;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class RollCall_OpenHelper extends SQLiteOpenHelper {
    //数据库名称
    public static final String ROLLCALL ="RollCall.db";
    //表UserInfo
    public static final String USERINFO ="userinfo";
    //用户名
    public static final String UID ="uid";
    //密码
    public static final String PASSWORD ="password";
    //姓名、授课老师
    public static final String UNAME ="uname";
    //表TeachInfo
    public static final String TEACHINFO="teachinfo";
    //班级号
    public static final String CID="cid";
    //班级名
    public static final String CNAME="cname";
    //表StudentInfo
    public static final String STUDENTINFO ="studentinfo";
    //学号
    public static final String SID ="sid";
    //学生姓名
    public static final String SNAME ="sname";
    //_id
    public static final String ID="_id";

    public RollCall_OpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version){
        super(context,name,factory,version);

    }

    @Override
    public void onCreate(SQLiteDatabase db){
        //创建表 userinfo,字段 _id , uid , password , uname
        db.execSQL("create table "+USERINFO+" ( "+ ID+" autoinc ,"+UID +" varchar(20),"+PASSWORD+" varchar(20),"+UNAME+" varchar(20))");
        //创建表 teachinfo , 字段 _id , cid , uname
        db.execSQL("create table "+TEACHINFO+" ( "+ID+" autoinc,"+CID+" varchar(20),"+CNAME+" varchar(20),"+UNAME+" varchar(20))");
        //创建表studentinfo , 字段 _id , sid , sname
        db.execSQL("create table "+STUDENTINFO+" ( "+ID+" autoinc ,"+SID+" varchar(20),"+SNAME+" varchar(20),"+CNAME+" varchar(20))");

        db.execSQL("insert into  userinfo ( _id ,uid,password,uname) values(?,?,?,?)",new String[]{"NULL","linjiajing","123","林嘉靖"});
        db.execSQL("insert into  teachinfo ( _id,cid,cname,uname) values(?,?,?,?)",new String[]{"NULL","131713","软工2班","林嘉靖"});
        db.execSQL("insert into  studentinfo ( _id,sid,sname,cname) values(?,?,?,?)",new String[]{"NULL","P131713439","梁亦清","软工2班"});
        db.execSQL("insert into  studentinfo ( _id,sid,sname,cname) values(?,?,?,?)",new String[]{"NULL","P131713440","林嘉靖","软工2班"});
        db.execSQL("insert into  studentinfo ( _id,sid,sname,cname) values(?,?,?,?)",new String[]{"NULL","P131713442","刘云宵","软工2班"});
    }

    @Override
    public   void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion){

    }
}
